package com.winit.common;

import java.util.Calendar;

public class SignGenerator {

    private static final String signInit = "G9tTZz5U+0oEylX7apPKv*ijYdbJVOQqh1FeS4s-BkCxgnHNAm8rwfWI/3uc2DLR6M";

    /**
     * 方法的作用：获取动态的签名字段：每5分钟变换一次
     * @author Michael.jin
     * @date 2017-06-13
     * @return
     */
    public static String getSign(){
        Calendar cal=Calendar.getInstance();
        int month=cal.get(Calendar.MONTH)+1;//得到月，因为从0开始的，所以要加1
        int day=cal.get(Calendar.DAY_OF_MONTH);//得到天
        int hour=cal.get(Calendar.HOUR);//得到小时
        int minute=cal.get(Calendar.MINUTE);//得到分钟
        //随机打乱的字符串(a-z,A-Z,0-9,+-*/)共66个字符
        int begin = month+day+hour;//最小值：1+1+0=2,最大值12+31+11=54
        int end = minute/5;//最小值：0,最大值:11
        String result = signInit.substring(begin, begin+end);
        int total = 0;
        char[] chr = result.toCharArray();
        for (char c : chr) {
            total += (int)c;
        }
        return String.valueOf(total);
    }
}
